package inits

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"go.uber.org/zap"
	"log"
	"weekly-exam/config"
	"weekly-exam/globar"
)

var ctx = context.Background()

func InitRedis() {
	data := config.ConappfigData.Redis
	addr := fmt.Sprintf("%s:%d", data.Host, data.Port)
	globar.Rdb = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: data.Password, // no password set
		DB:       0,             // use default DB
	})

	err := globar.Rdb.Set(ctx, "key", "value", 0).Err()
	if err != nil {
		panic(err)
	}
	sufo, _ := zap.NewProduction()
	sufo.Info("Redis is success")

	log.Println("redis is success")
}
